import axios from 'axios'
import { Message } from 'element-ui';
const request = axios.create({
  // baseURL: 'http://192.168.1.2:3000',
  baseURL: 'http://localhost:3000',
  timeout: 1000
})

request.interceptors.request.use(config => {
  // config.headers.Authorization = window.sessionStorage.getItem('token')
  // config.headers = {
  //   'Content-Type': 'multipart/form-data',
  // }
  return config
}, err => {
  console.log(err)
  Message.error({ message: '网络错误' });
  // console.log('网络错误');
})

request.interceptors.response.use(res => {
  return res.data
}, err => {

  if (err.response && err.response.status) {
    // 错误请求的状态码
    let status = err.response.status
    if (status === 400) {
      Message.error({ message: '参数错误' });
    }
    if (status === 401) {
      Message.error({ message: '登录过期,请重新登录' });


    }
    if (status === 403) {
      Message.error({ message: '没有权限' });


    }
    if (status === 404) {
      Message.error({ message: '接口路径错误' });


    }
    if (status === 500) {
      Message.error({ message: '服务器出错' });


    }
    if (status === 503) {
      Message.error({ message: '服务器在维护' });


    }
  }
})

export default request